package com.zhiwei.msf.gateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhiwei.msf.common.constant.ResultResponseMsg;
import com.zhiwei.msf.common.dto.PageDataDto;
import com.zhiwei.msf.common.util.BeanConverterUtil;
import com.zhiwei.msf.gateway.controller.vo.QueryRouteInfoVo;
import com.zhiwei.msf.gateway.dto.QueryRouteInfoDto;
import com.zhiwei.msf.gateway.dto.RouteInfoDto;
import com.zhiwei.msf.gateway.service.RouteInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * function: 路由服务
 * author: zhiwei_yang
 * time: 2020/2/14-18:31
 */
@RestController
@RequestMapping("/route")
@Api(tags = "路由服务")
public class RouteController {

    @Autowired
    private RouteInfoService routeInfoService;

    /**
     * 查询路由信息
     *
     * @param queryRouteInfoVo
     * @return
     */
    @PostMapping("/queryRouteInfo")
    @ApiOperation("查询路由信息")
    public ResultResponseMsg queryRouteInfoByPage(@RequestBody QueryRouteInfoVo queryRouteInfoVo) {
        PageDataDto<RouteInfoDto> pageDataDto = routeInfoService.queryRoutInfoByPage(BeanConverterUtil.convertToBean(queryRouteInfoVo, QueryRouteInfoDto.class));
        return ResultResponseMsg.buildSuccessResultMsg(pageDataDto);
    }

    /**
     * 同步服务路由信息到数据库
     *
     * @param
     * @return
     */
    @GetMapping("/loadServiceRouteToDB")
    @ApiOperation("同步服务路由信息到数据库")
    public ResultResponseMsg loadServiceRouteToDB() {
        routeInfoService.loadServiceRouteToDB();
        return ResultResponseMsg.buildSuccessResultMsg();
    }
}